package game.components;


import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Fabricio
 */
public class Bomba {
    private Image imagem = null;
    private int maxX, maxY, x, y;
    private int passoX = 3, passoY = 1;
    private boolean visible;

    public Bomba(int maxX, int maxY, int x, int y, boolean visible) {
        this.maxX = maxX;
        this.maxY = maxY;
        this.x = x;
        this.y = y;
        this.visible = visible;
        try {
            imagem = Image.createImage("/images/bomba.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    public void paint(Graphics g) {
        if (this.visible)
            g.drawImage(this.getImagem(), this.getX(), this.getY(), Graphics.HCENTER | Graphics.VCENTER);
    }
    
    public void mexe() {
        if ( y > (getMaxY()-20) ) {
            this.setVisible(false);//invisible
        }
        if (visible){
            y += passoY;
            if(x < 0 || x > getMaxX()){
                inverteX();
                x += passoX;
            }
        }
    }
    
    public boolean testaColisao(Tank t) {
        if ( t.getMaxY() >= this.getMinY()
                && t.getMinY() <= (this.y + this.getHeight() / 2) ) {
            if (t.getMinX() <= this.x
                    && t.getMaxX() >= this.x) {
//                    b.acertou(this);
//                    b.invisible();
//                    b.setY(maxY - 25);
//                    this.invisible();
                System.out.println("colidiu...");
                return true;
            }
        }
        return false;
    }
    
    public void inverteX(){
        passoX = -passoX;
    }

    public Image getImagem() {
        return imagem;
    }

    public void setImagem(Image imagem) {
        this.imagem = imagem;
    }

    public int getMaxX() {
        return maxX;
    }

    public void setMaxX(int maxX) {
        this.maxX = maxX;
    }

    public int getMaxY() {
        return maxY;
    }

    public void setMaxY(int maxY) {
        this.maxY = maxY;
    }

    public int getPassoX() {
        return passoX;
    }

    public void setPassoX(int passoX) {
        this.passoX = passoX;
    }

    public int getPassoY() {
        return passoY;
    }

    public void setPassoY(int passoY) {
        this.passoY = passoY;
    }

    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
    
    public int getMinY() {
        return this.getY() - this.getHeight()/2;
    }

    public int getMinX() {
        return this.getX() - this.getWidth()/2;
    }
    
    public int getWidth() {
        return imagem.getWidth();
    }

    public int getHeight() {
        return imagem.getHeight();
    }
}
